﻿/// <reference path="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2-vsdoc.js" /> 

$(document).ready(function () {
    $(".ArticleLocation_Data").mouseenter(function () {


        $("#mapOuter").css("top", "").css("left", "");
        var coords = $(this).attr("data-latlon");
        var title = $(this).attr("data-title");
        $("#mapOuter").fadeIn(500);
        $("#mapOuter").position({
            my: "left center",
            at: "right+25 center",
            of: $(this).find(".coordsSpan")
        });     
        initializeMap(coords, title);
        
    }).mouseleave(function () {
        $("#mapOuter").fadeOut();
    });

    $("#mapOuter").mouseenter(function () {
        $("#mapOuter").stop();
        $(this).mouseleave(function() {
            $("#mapOuter").fadeOut();
        });
    });
});

function initializeMap(coords, title) {
    var map = null;
    var lat = parseInt(coords.split(",")[0]);
    var lon = parseInt(coords.split(",")[1]);
    var mapOptions = {     
        center: new google.maps.LatLng(lat, lon),
        zoom: 5,
        mapTypeId: google.maps.MapTypeId.TERRAIN
    };
    map = new google.maps.Map(document.getElementById("mappingContainer"),
        mapOptions);

    var centerMarker = new google.maps.Marker({
	    position: new google.maps.LatLng(lat, lon),
	    map: map
    });

    infoBubble = new InfoBubble({
        content: "<div class='infoWindow'> " + title + " </div>",
        padding: 10,
        minWidth: 150
    });
    infoBubble.open(map, centerMarker);
}
